Skip to content

feat(virtq): use Rc pointer equality instead if generation for pools - #1945

Open
andreiltd wants to merge 1 commit into
hyperlight-dev:mainfrom
andreiltd:virtq-pool-inst
Open

andreiltd wants to merge 1 commit into
hyperlight-dev:mainfrom
andreiltd:virtq-pool-inst

Conversation

@andreiltd

Copy link
Copy Markdown
Member

Instead of threading generation through pools it's actually simpler to use Rc::ptr_eq to check if pool belongs to current snapshot generation and swap pools on restore.

Copilot AI balanced review requested due to automatic review settings October 16, 2026 12:10
@andreiltd andreiltd added the kind/refactor For PRs that restructure or remove code without adding new functionality. label Oct 16, 2026
@andreiltd andreiltd changed the title feat(virtq): use Rc pointer equality instead generation for pools feat(virtq): use Rc pointer equality instead if generation for pools Oct 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Reservation validation rejects every nonempty pool swap, causing restore failures with retained buffers and posted chains.

1 open finding
What changed in this PR

This PR uses shared pool identity to track virtqueue allocation ownership across snapshot restores.

Changes:

  • Replace pool generation counters with Rc pointer identity and pool swaps.
  • Keep retained leases tied to their original pools.
  • Expand swap tests and update transport documentation.
File Description
src/​hyperlight_host/​tests/​integration_test.rs Rename the retained-buffer test.
src/​hyperlight_guest/​src/​transport/​context.rs Clarify pool ownership and restore safety comments.
src/​hyperlight_guest/​src/​transport/​backing.rs Update alias allocator terminology.
src/​hyperlight_common/​src/​virtq/​producer.rs Swap pools while preserving posted chains.
src/​hyperlight_common/​src/​virtq/​pool/​tests.rs Test swap reservations, ordering, and validation.
src/​hyperlight_common/​src/​virtq/​pool/​slot.rs Implement pool identity and replacement allocation state.
src/​hyperlight_common/​src/​virtq/​buffer.rs Return leases to their original pools.
docs/​virtio-host-guest-communication.md Document pool swaps and retained ownership.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/hyperlight_common/src/virtq/pool/slot.rs
@hyperlight-gh-bot

This comment has been minimized.

@andreiltd
andreiltd force-pushed the virtq-pool-inst branch 3 times, most recently from 4062922 to 97d57b1 Compare October 19, 2026 14:25
@hyperlight-gh-bot

This comment has been minimized.

Instead of threading generation through pools it's actually simpler to
use Rc::ptr_eq to check if pool belongs to current snapshot generation
and swap pools on restore.

Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: 7e26042c3a33
Baseline commit: f0934723ebf0

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 751.77 ns (➖ 1.01x slower)
vec_bytes 581.53 ns (➖ 1.00x faster)
382.00 µs (➖ 1.02x slower)

payload_allocation

slot_pool_segmented
65536 145.10 ns (➖ 1.19x faster)
262144 521.77 ns (➖ 1.01x faster)

sandboxes

create_initialized_and_drop
medium 83.98 ms (➖ 1.01x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
7.76 ns (➖ 1.00x faster) 7.77 ns (➖ 1.01x slower) 7.77 ns (➖ 1.00x slower)

snapshot_files

load_snapshot_unverified
small 93.06 µs (➖ 1.00x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
65536 2.11 µs (➖ 1.09x slower) 1.98 µs (➖ 1.06x faster)
262144 7.73 µs (➖ 1.10x slower) 6.95 µs (➖ 1.06x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 6.54 µs (➖ 1.03x faster) 6.19 µs (➖ 1.06x faster)
8192 1.06 µs (➖ 1.05x faster) 1.06 µs (➖ 1.01x slower)
262144 28.20 µs (➖ 1.02x slower)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 695.29 ns (➖ 1.02x faster)
vec_bytes 500.50 ns (➖ 1.03x faster)
656.36 µs (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 152.29 ns (➖ 1.12x slower)
262144 514.85 ns (➖ 1.02x faster)

sandboxes

create_initialized_and_drop
medium 75.89 ms (➖ 1.01x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
7.06 ns (➖ 1.02x faster) 7.00 ns (➖ 1.02x faster) 6.96 ns (➖ 1.02x faster)

snapshot_files

load_snapshot_unverified
small 45.73 µs (➖ 1.00x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
65536 2.12 µs (➖ 1.01x slower) 2.10 µs (➖ 1.01x faster)
262144 7.59 µs (➖ 1.01x slower) 7.51 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 6.94 µs (➖ 1.06x faster) 7.04 µs (➖ 1.04x faster)
8192 740.86 ns (➖ 1.05x faster) 721.70 ns (➖ 1.04x faster)
262144 30.73 µs (➖ 1.03x faster)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 941.46 ns (➖ 1.02x slower)
vec_bytes 711.56 ns (➖ 1.02x slower)
315.34 µs (➖ 1.02x faster)

payload_allocation

slot_pool_segmented
65536 185.75 ns (➖ 1.02x slower)
262144 670.13 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 60.16 ms (➖ 1.06x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
9.95 ns (➖ 1.03x faster) 10.30 ns (➖ 1.04x slower) 9.91 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 86.23 µs (➖ 1.01x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
65536 2.63 µs (➖ 1.02x faster) 2.50 µs (➖ 1.02x slower)
262144 9.02 µs (➖ 1.02x faster) 9.05 µs (➖ 1.01x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.10 µs (➖ 1.03x faster) 7.99 µs (➖ 1.02x faster)
8192 1.52 µs (➖ 1.11x slower) 1.31 µs (➖ 1.01x faster)
262144 34.89 µs (➖ 1.02x faster)
mshv3 / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 929.97 ns (➖ 1.01x faster)
vec_bytes 746.17 ns (➖ 1.13x slower)
696.35 µs (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 171.67 ns (➖ 1.02x faster)
262144 640.88 ns (➖ 1.02x faster)

sandboxes

create_initialized_and_drop
medium 66.80 ms (➖ 1.01x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
8.82 ns (➖ 1.08x faster) 8.82 ns (➖ 1.06x faster) 8.84 ns (➖ 1.10x faster)

snapshot_files

load_snapshot_unverified
small 48.36 µs (➖ 1.09x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
65536 2.28 µs (➖ 1.00x slower) 2.32 µs (➖ 1.03x slower)
262144 7.99 µs (➖ 1.02x faster) 7.96 µs (➖ 1.01x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 7.50 µs (➖ 1.01x faster) 7.43 µs (➖ 1.04x faster)
8192 900.85 ns (➖ 1.07x faster) 916.64 ns (➖ 1.00x faster)
262144 39.95 µs (➖ 1.00x slower)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.15 µs (➖ 1.01x slower)
vec_bytes 786.95 ns (➖ 1.01x slower)
1.85 ms (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 239.98 ns (➖ 1.02x slower)
262144 796.35 ns (➖ 1.02x slower)

sandboxes

create_initialized_and_drop
medium 78.39 ms (➖ 1.06x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
10.93 ns (➖ 1.08x faster) 10.15 ns (➖ 1.08x faster) 10.11 ns (➖ 1.05x faster)

snapshot_files

load_snapshot_unverified
small 698.73 µs (➖ 1.10x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
65536 2.38 µs (➖ 1.01x faster) 2.34 µs (➖ 1.01x slower)
262144 9.04 µs (➖ 1.07x faster) 9.14 µs (➖ 1.02x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 9.93 µs (➖ 1.09x slower) 8.80 µs (➖ 1.00x slower)
8192 1.30 µs (➖ 1.09x faster) 1.30 µs (➖ 1.01x faster)
262144 40.06 µs (➖ 1.04x slower)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.19 µs (➖ 1.01x slower)
vec_bytes 769.48 ns (➖ 1.00x faster)
2.91 ms (➖ 1.04x faster)

payload_allocation

slot_pool_segmented
65536 216.03 ns (➖ 1.02x slower)
262144 765.15 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 105.72 ms (➖ 1.02x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
11.10 ns (➖ 1.10x slower) 10.19 ns (➖ 1.01x faster) 10.90 ns (➖ 1.08x slower)

snapshot_files

load_snapshot_unverified
small 574.17 µs (➖ 1.11x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
65536 2.39 µs (➖ 1.03x slower) 2.33 µs (➖ 1.02x faster)
262144 7.80 µs (➖ 1.02x slower) 7.81 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.44 µs (➖ 1.02x faster) 8.37 µs (➖ 1.07x faster)
8192 1.14 µs (➖ 1.09x faster) 1.09 µs (➖ 1.02x faster)
262144 44.11 µs (➖ 1.03x slower)

Reported by cargo ci bench-report --candidate run:39464068872 --config-file bench_report.toml.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor For PRs that restructure or remove code without adding new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants